package VektoriTesti;

import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;

/**
 *
 * @author Smai
 */
public class Main implements MouseListener, MouseMotionListener {

  private Canvas canvas;

  public Main() {

    canvas = new Canvas();
    JFrame frame = new JFrame();

    canvas.addMouseListener(this);
    canvas.addMouseMotionListener(this);

    frame.setPreferredSize(new Dimension(700, 700));
    frame.add(canvas);
    frame.setResizable(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    frame.setFocusable(false);
    frame.setLocation(400, 300);
    canvas.requestFocus();
  }

  //Hiirikuuntelijat
  public static void main(String[] args) {
    Main main = new Main();
    main.loop();
  }

  public void loop() {
    while (true) {
      try {

        for (int i = 0; i < canvas.pallot.size(); i++) {
          canvas.pallot.get(i).laskeKulma();
        }

        canvas.repaint();

        Thread.sleep(10);
      } catch (Exception e) {
      }
    }
  }

  public void mouseClicked(MouseEvent e) {
    canvas.pallot.clear();
    canvas.pallot.add(new Pallo(300, 300, 5, e.getX(), e.getY()));
  }

  public void mousePressed(MouseEvent e) {
  }

  public void mouseReleased(MouseEvent e) {
  }

  public void mouseEntered(MouseEvent e) {
  }

  public void mouseExited(MouseEvent e) {
  }

  public void mouseDragged(MouseEvent e) {
  }

  public void mouseMoved(MouseEvent e) {
    canvas.mouseX = e.getX();
    canvas.mouseY = e.getY();
  }
}
